<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab栏切换</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .tab{
            width: 540px;
        }
        .tablist li {
            float: left;
            height: 39px;
            line-height: 39px;
            padding: 0 20px;
            text-align: center;
            cursor: pointer;
        }

        .tablist .current {
            background-color: #c81623;
            color: #fff;
        }

        .iteminfo {
            padding: 20px 0 0 20px;
        }

        .item {
            display: none;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tablist">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后服务</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tabcon">
            <div class="item" style="display: block;">
                商品介绍模块内容
            </div>
            <div class="item">
                规格与包装模块内容
            </div>
            <div class="item">
                售后保障模块内容
            </div>
            <div class="item">
                商品评价(50000) 模块内容
            </div>
            <div class="item">
                手机社区模块内容
            </div>
        </div>
    </div>
    <script>
        var tablist = document.querySelector('.tablist');
        var lis = tablist.querySelectorAll('li');
        var items = document.querySelectorAll('.item')
        for (var i = 0; i < lis.length; i++) {
            lis[i].setAttribute('index', i)
            //  第一个模块
            lis[i].onclick = function () {
                for (var i = 0; i < lis.length; i++) {
                    lis[i].className = '';
                }
                this.className = 'current';

                // 第二个模块
                var index = this.getAttribute('index');
                for (var i = 0; i < lis.length; i++) {
                    items[i].style.display = 'none'
                } 
                items[index].style.display = 'block'
            }
        }
    </script>
</body>

</html> 